var path=require('path');
var webpack=require('webpack');
var debug=process.env.NODE_ENV !=="production";
var ROOT_PATH=path.resolve(__dirname);
var APP_PATH=path.resolve(ROOT_PATH,'./src');
var BUILD_PATH=path.resolve(ROOT_PATH,'./__build');
var NODE_PATH=path.resolve(ROOT_PATH,'./node_modules');
var pathToReact = path.resolve(NODE_PATH, 'react/dist/react.js');
var pathToReactDOM = path.resolve(NODE_PATH, 'react-dom/dist/react-dom.min.js');
var ExtractTextPlugin = require('extract-text-webpack-plugin');

// multiple extract instances
var extractCSS = new ExtractTextPlugin('style/[name].css');
var extractLESS = new ExtractTextPlugin('style/[name].less');

module.exports={
	entry: {
			vendor:['react','react-dom','redux','react-redux'],

			index:['webpack-dev-server/client?http://localhost:8080', // WebpackDevServer host and port
			'webpack/hot/only-dev-server',
			'./src/Todos.js' // Your appʼs entry point]
		]
	},
	output:{
		path:'__build',
		filename:'bundle.js',
		 publicPath: '/'
	},
	resolve:{
		root: [process.cwd() + '/src', process.cwd() + '/node_modules'],
		 extensions: ['', '.js', '.css', '.scss', '.ejs', '.png', '.jpg'],
		  alias:{
		 	'react':pathToReact,
		 	'react-dom':pathToReactDOM,
		 	'redux':path.join(NODE_PATH,'redux/dist/redux.js'),
		 	'react-redux':path.join(NODE_PATH,'react-redux/dist/react-redux.js')
		 }
	},
	devtool:'eval-source-map',
	devServer:{
		historyApiFallBack:'true',
		hot:true,
		inline:true,
		progress:true
	},
	 module: {
	 	noParse : [pathToReact,pathToReactDOM],
	    loaders: [
	     
	      { test: /\.js$/, loader: 'babel', query: {compact: false} }
	     ,
	     { test: /\.jsx?$/, loader: 'babel', query: {compact: false} }
	     ,
	      {
	      	test: /(\.css|\.scss)$/i, 
	      	  exclude: [NODE_PATH],
	      	loader: extractCSS.extract(['css','sass']),

	      },
 		{test: /\.(jpe?g|png|gif)$/i, loaders: ['url-loader?limit=10000&name=images/[name].[ext]']},
	    ]
	},
	jshint:{
		"esnext":true
	},
	plugins:[
		
      new webpack.NoErrorsPlugin(),
      new webpack.HotModuleReplacementPlugin(),
      extractCSS,
      extractLESS,
      new webpack.optimize.CommonsChunkPlugin(/* chunkName = */"vendor", /* filename= */"vendor.bundle.js")
	]
}
